import jsonp from "jsonp"
import request from "./request"



// // 请求登录的数据
// export const ReqLogin = (formMessage) => axios.post("/login", formMessage);
export const ReqLogin = (formMessage) => request("post","/login", formMessage);




// 请求天气的数据
export const JsonpRequest = (city) => {
    return new Promise((res, rej) => {
        const url = 'http://api.map.baidu.com/telematics/v3/weather?location=' + city + '&output=json&ak=3p49MVra6urFRGOT9s8UBWr2&callback=__jp1'
        jsonp(url, {}, function (err, data) {
            if (!data.error) {
                data.results[0].weather_data[0].city=city;
                res(data.results[0].weather_data[0])
            } else {
                res("非法城市名")
            }
        })
    })
}

// 添加分类
// export const CategoryAdd =(categorydata)=>{
//    return axios.post("/category/add",categorydata)
// }
export const CategoryAdd =(categorydata)=>request("post","/category/add",categorydata)

// 获取分类
// export const CategoryGet=(categoryGrade)=>axios.get("/category/get",{
//     params: categoryGrade
// })
export const CategoryGet=(cagetoryGrade)=>request("get","/category/get",cagetoryGrade);

//更新分类名
// export const CategoryUpate=(Name)=>axios.post("/category/updatename" ,Name)
export const CategoryUpate=(Name)=>request("post","/category/updatename" ,Name)

// 根据分类ID获取分类名
export const CategoryName=(args)=>request("get","/category/name",args)

// 删除商品图片
export const RemoveImg=(Name)=>request("post","/image/remove",Name)

// 添加商品 
export const ProductAdd=(product)=>request("post","/product/add",product)

// 获取商品 args是一个对象包含 页码page 和每页请求的数据个数 number
export const ProductGet=(args)=>request("post","/product/get",args)

// 查找商品
export const SearchProduct=(args)=>request("get" ,"/product/search",args)

// 更新商品信息
export const ProductUpdate=(args)=>request("post","/product/update",args)

// 删除商品
export const RemoveProduct=(args)=>request("post","/product/remove",args)

// 添加角色
export const RoleAdd=(args)=>request("post","/role/add",args)

// 获取所有角色
export const RoleGet=()=>request("get","/role/get")

// 获取单个角色
export const SingleRole=(args)=>request("get","/role/singlerole",args)

// 更新角色信息
export const RoleUpdate=(args)=>request("post","/role/update",args)

// 添加用户
export const UserAdd=(args)=>request("post","/user/add",args)

// 获取用户
export const UserGet=()=>request("get","/user/get")

// 修改用户信息
export const UserUpdate=(args)=>request("post","/user/update",args)

// 删除用户
export const UserDelete=(args)=>request("post","/user/delete",args)

